﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;


namespace MKB.TimePicker
{
    /// <summary>
    /// Enables only TimeSelector controls to be listed in the Design Time ControlToValidate dropdown.
    /// </summary>
    public class TimeSelectorValidationControlConverter : ValidatedControlConverter
    {
        private object[] GetControls(IContainer container)
        {
            ArrayList list = new ArrayList();
            foreach (IComponent comp in container.Components)
            {
                TimeSelector ts = comp as TimeSelector;
                if (ts != null)
                {
                    if (ts.ID != null && ts.ID.Trim().Length > 0)
                    {
                        list.Add(ts.ID);
                    }
                }
            }
            list.Sort(Comparer.Default);
            return list.ToArray();
        }

        public override StandardValuesCollection GetStandardValues(
            ITypeDescriptorContext context)
        {
            if (context == null || context.Container == null) return null;
            object[] controls = GetControls(context.Container);
            if (controls != null)
                return new StandardValuesCollection(controls);
            return null;
        }

    }
}
